<div class="SipeiMain_r fr">
    <h2 class="clearfix fonts_18 height45 fontc_444"><?php echo $this->title;?></h2>
    <?php
    $form = $this->beginWidget('CActiveForm', array(
    'action' => Yii::app()->createUrl($this->route),
    'method' => 'get',
    'id' => 'searchForm'
    ));
    ?>
            <ul class="clearfix back_bgf border_3 border_c pr30 pl30 pt20 pb20 height32 fontc_666">
                <li class="fl pt10 pr20 pb10 pl20">
                    <span class="pr3 pl2">代码：</span><input type="text" name="code" value="<?php echo $serch['code']; ?>" class="pt6 pr5 pb6 pl5 border_3 border_c fontc_666 w100" />
                </li>
                <li class="fl pt10 pr30 pb10 pl3">
                    <span class="pr3">规则名称：</span><input type="text" name="name" value="<?php echo $serch['name']; ?>" class="pt6 pr5 pb6 pl5 border_3 border_c fontc_666 w100" />
                </li>           
                <li class="fr pt10 pb10">
                    <input type="submit" value="查询" class="b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
                </li>
            </ul>
    <?php
    $this->endWidget();
    ?>
    <div class="clearfix back_bgf border_c mt15 pt20 pb20">
            <div class="clearfix pb20 pl30">
                <input type="button" value="新增" onclick="add();" style="margin-right:30px;" class="fr b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
            	<input type="button" value="删除" onclick="delete_all()" class="fl b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
            </div>
            <table class="height40">
                <thead class="back_bgf5 fontc_666">
                    <tr>
                    	<th width="8%" align="center" class="m_hr_t m_hr_b pl30"><input type="checkbox" class="checkboxs"></th>
                        <th width="100" align="center" class="m_hr_t m_hr_b">代码</th>
                        <th width="200" align="center" class="m_hr_t m_hr_b">规则名称</th>
                        <th width="90" align="center" class="m_hr_t m_hr_b">是否生效</th>
                        <th width="260" align="left" class="m_hr_t m_hr_b">备注</th>
                        <th width="148" align="center" class="m_hr_t m_hr_b">操作</th>
                    </tr>
                </thead>
                <tbody class="fontc_444">
                    <?php if(!empty($data)): ?>
                        <?php foreach($data as $value):?>
                        <tr>
                        	<td align="center" class="m_hr_b pl30"><input type="checkbox" name="deleteAll[]" value="<?php echo $value['id'];?>" class="checkbox"></td>
                            <td align="center" class="m_hr_b pt8 pr5 pb8 pl5 height24">
                                <?php echo $value['code']; ?>
                            </td>
                            <td align="center" class="m_hr_b pt8 pr5 pb8 pl5 height24">
                                <?php echo $value['name']; ?>
                            </td>
                            <td align="center" class="m_hr_b">
                                <input type="checkbox" <?php echo $value['status'] == 1 ? 'checked=checked' : '';?> disabled />
                            </td>
                            <td align="left" class="m_hr_b pt8 pr5 pb8 pl5 height24">
                                <p><?php echo $value['remark']; ?></p>
                            </td>
                            <td align="center" class="m_hr_b">
                                <p class="clearfix pl30" style="height:15px;">
                                    <a href="<?php echo $this->createUrl('/nojoin_rule/detail/index')?>?id=<?php echo $value['id']; ?>" class="fl ml10" title="规则字段设置"><img src="/themes/default/images/Sipei/plus.png"/></a>
                                    <img src="/themes/default/images/Sipei/edit.png" title="编辑" class="fl ml10 cursor" onclick="update(<?php echo $value['id']; ?>)" />
                                    <img src="/themes/default/images/Sipei/delate.png" title="删除" onclick="set_ok(<?php echo $value['id']; ?>,<?php echo $value['status'];?>)" class="fl ml10 cursor" />
                                </p>
                            </td>
                        </tr>
                        <?php endforeach;?>
                    <?php else: ?>
                        <tr>
                            <td colspan="6"  align="center"><h1>暂无数据</h1></td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
            <?php $this->renderPartial('//partial/partial_pager', array('pages' => $pages,"url"=>$pageUrl)); ?>
    </div>
</div>
	
<script>
function set_ok(id,is_del) {
	$.dialog.confirm('确定删除吗', function() {
		$.get('/nojoin_rule/default/delete_all', {id: id}, function(data) {
			if(data == 1){
		       	 location.reload();
		     }else if(data == 3){
				 $.dialog.alert("请清空规则字段设置数据后再进行删除操作");
				 return false;
			 }else{
				 $.dialog.alert("删除失败");
				 return false;
			}          
		});
	});
}
function delete_all(){
	var aa='';
	$("input[name='deleteAll[]']:checkbox:checked").each(function(){
		aa+=$(this).val()+',';
	});
	if(aa == ''){
		$.dialog.alert("请选择要删除条目");
		return false;
	}
	$.dialog.confirm('确定删除所选数据吗', function() {
		aa+=0;
		$.get('/nojoin_rule/default/delete_all', {id: aa}, function(data) {
			if(data == 1){
		       	 location.reload();
		     }else if(data == 3){
				 $.dialog.alert("请清空规则字段设置数据后再进行删除操作");
				 return false;
			 }else{
				 $.dialog.alert("删除失败");
				 return false;
			}          
		});
	});
}
function add() {
	api = $.dialog({
		id: 'testID2',
		lock: true,
		padding:0,
		fixed: true,
		title:"新增",
		width:480,
		height:400,
		max: false,
		min: false
	});
	$.get('/nojoin_rule/default/add',function(html){
		api.content(html);
	});
}
function update(id) {
	api = $.dialog({
		id: 'testID2',
		lock: true,
		padding:0,
		fixed: true,
		title:"编辑",
		width:480,
		height:400,
		max: false,
		min: false
	});
	$.post('/nojoin_rule/default/update',{id:id,time:new Date()},function(html){
		api.content(html);
	});
}
$(function() {
	$(".checkboxs").click(function() {
		var checkedS = $(this).attr("checked");
		if (checkedS) {
			$(".checkbox").attr("checked", true)
		} else {
			$(".checkbox").removeAttr("checked")
		}
	})

})
</script>